
import { Entity , Column ,PrimaryGeneratedColumn,CreateDateColumn, UpdateDateColumn, JoinColumn, ManyToOne, ManyToMany, JoinTable, } from "typeorm";
import { ApiProperty } from "@nestjs/swagger";

import { UserEntity } from "./../user/user.entity";
import {TagsEntity} from './../tag/tag.entity'

@Entity({name:'tyk_blog'})
export class BlogEntity {
    @ApiProperty({description:'主键'})
    @PrimaryGeneratedColumn({name:'blog_id'})
    blogId:number

    @ApiProperty({description:'标题'})
    @Column()
    title:string

    @ApiProperty({description:'存储内容'})
    @Column({type:'text'})
    content:string
    
    @ApiProperty({description:'页面展示内容'})
    @Column({name:'html_content',type:'text'})
    htmlContent:string

    @ApiProperty({description:'是否发布,默认不发布'})
    @Column({name:'is_release',default:false})
    isRelease:boolean


    @ApiProperty({description:'创建时间'})
    @CreateDateColumn({ type: 'timestamp', name: 'create_date', comment: '创建时间' })
    createDate: Date

    @ApiProperty({description:'更新时间'})
    @UpdateDateColumn({ type: 'timestamp', name: 'update_date', comment: '更新时间' })
    updateDate: Date

    @Column({name:'user_id'})
    userId:number

    @ManyToOne((type)=>UserEntity,(user)=>user.blogs)
    @JoinColumn({name:'user_id'})
    user:UserEntity

    @ManyToMany((type)=>TagsEntity,(tag)=> tag.blogs)
    @JoinTable({
        name: 'tyk_blog_tag',
        joinColumns: [
          {name: 'blog_id'},
        ],
        inverseJoinColumns: [
          {name: 'tag_id'},
        ],
      })
    tags:TagsEntity[]
}